<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<tiles:importAttribute/>
<div id="${PORTLET_INSTANCE_ID}" class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">
	<div class="portlet-header ui-widget-header ui-corner-all"><span class="ui-icon ui-icon-minusthick"></span><a>${title }</a></div>
	<div class="portlet-content"  style="height:${HEIGHT}">
		<table class="tableInit">
       		<tr>
       			<td>Subject:</td>
       			<td><input id="mail_subject" style="width:300px" type="text" /></td>
       		</tr>
       		<tr>
       			<td>To:</td>
       			<td><input id="mail_recipients" style="width:300px" type="text" /></td>
       		</tr>
       		<tr>
       			<td>Content:</td>
       			<td>
       				<textarea id="mail_content" rows="20" cols="100"></textarea>
       			</td>
       		</tr>
       		<tr>
       			<td>&nbsp; </td>
       			<td><input class="send_mail" type="submit" value="发送">&nbsp;&nbsp;&nbsp;<input class="form_clear" type="submit" value="清除"> </td>
       		</tr>
		</table>
       	<div class="status"></div>
       	<div class="write_mail" style="display:none;"><input class="write_mail_btn" type="submit" value="写邮件"></div>
       	
		
	</div>
</div>
<script type="text/javascript">
<!--
$(function() {
	
	var $PORTLET_INSTANCE = $('#'+ '${PORTLET_INSTANCE_ID}');
	var $portlet_content = $PORTLET_INSTANCE.find('.portlet-content');
	// send mail
	$PORTLET_INSTANCE.find('.send_mail').click(function(){
		var subject = $PORTLET_INSTANCE.find('#mail_subject').val();
		var to = $PORTLET_INSTANCE.find('#mail_recipients').val();
		var content = $PORTLET_INSTANCE.find('#mail_content').val();
		if(to == '' || content == ''){
			 $PORTLET_INSTANCE.find('.status').text("收件人或者内容不能为空!");
			return false;
		}
		$portlet_content.mask("Mail Sending...");
		$.ajax({
			type:'post',
			data:{subject: subject, recipients_str: to,mailContent: content},
			url:'${ctx}/goal/mail.action',
			success:function(){
				//alert("successfully!");
				 $portlet_content.unmask();
				 $PORTLET_INSTANCE.find('.status').text("Mail send successfully!");
				 $PORTLET_INSTANCE.find('.tableInit').hide();
				 $PORTLET_INSTANCE.find('.write_mail').show();
				 
			}
		});
	});
	// clear form content
	$PORTLET_INSTANCE.find('.form_clear').click(function(){
		$PORTLET_INSTANCE.find('#mail_subject').val('');
		$PORTLET_INSTANCE.find('#mail_recipients').val('');
		$PORTLET_INSTANCE.find('#mail_content').val('');
		$PORTLET_INSTANCE.find('.status').text("");
	});
	// back to mail sender page
	$PORTLET_INSTANCE.find('.write_mail_btn').click(function(){
		 $PORTLET_INSTANCE.find('.tableInit').show();
		 $PORTLET_INSTANCE.find('.form_clear').click();
		 $PORTLET_INSTANCE.find('.write_mail').hide();
		 $PORTLET_INSTANCE.find('.status').text("");
	});
});
//-->
</script>
	